import 'package:finance_app/src/entities/payment_term_entity.dart';

paymentTermEntityFromJson(PaymentTermEntity data, Map<String, dynamic> json) {
	if (json['id'] != null) {
		data.id = json['id'] is String
				? int.tryParse(json['id'])
				: json['id'].toInt();
	}
	if (json['company_id'] != null) {
		data.companyID = json['company_id'] is String
				? int.tryParse(json['company_id'])
				: json['company_id'].toInt();
	}
	if (json['name'] != null) {
		data.name = json['name'].toString();
	}
	if (json['description'] != null) {
		data.description = json['description'].toString();
	}
	if (json['payment_term_type'] != null) {
		data.paymentTermType = json['payment_term_type'].toString();
	}
	if (json['due_after'] != null) {
		data.dueAfter = json['due_after'] is String
				? int.tryParse(json['due_after'])
				: json['due_after'].toInt();
	}
	if (json['is_default_for_customer'] != null) {
		data.isDefaultForCustomer = json['is_default_for_customer'] is String
				? int.tryParse(json['is_default_for_customer'])
				: json['is_default_for_customer'].toInt();
	}
	if (json['is_default_for_supplier'] != null) {
		data.isDefaultForSupplier = json['is_default_for_supplier'] is String
				? int.tryParse(json['is_default_for_supplier'])
				: json['is_default_for_supplier'].toInt();
	}
	if (json['created_by'] != null) {
		data.createdBy = json['created_by'].toString();
	}
	if (json['created_at'] != null) {
		data.createdAt = json['created_at'].toString();
	}
	if (json['updated_at'] != null) {
		data.updatedAt = json['updated_at'].toString();
	}
	return data;
}

Map<String, dynamic> paymentTermEntityToJson(PaymentTermEntity entity) {
	final Map<String, dynamic> data = new Map<String, dynamic>();
	data['id'] = entity.id;
	data['company_id'] = entity.companyID;
	data['name'] = entity.name;
	data['description'] = entity.description;
	data['payment_term_type'] = entity.paymentTermType;
	data['due_after'] = entity.dueAfter;
	data['is_default_for_customer'] = entity.isDefaultForCustomer;
	data['is_default_for_supplier'] = entity.isDefaultForSupplier;
	data['created_by'] = entity.createdBy;
	data['created_at'] = entity.createdAt;
	data['updated_at'] = entity.updatedAt;
	return data;
}